home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / tex-k / tex-k-archive.past / tex-k-archive.gz / tex-k-archive / 000128_savior@wam.umd.edu_Fri Dec 17 03:00:29 1993.msg < prev    next >
Internet Message Format  |  1994-10-11  |  8KB

  1. Received: from pg2-srv.wam.umd.edu by cs.umb.edu with SMTP id AA09943
  2.   (5.65c/IDA-1.4.4 for <tex-k@cs.umb.edu>); Fri, 17 Dec 1993 08:00:32 -0500
  3. Received: from next18pg2.wam.umd.edu by pg2-srv.wam.umd.edu with SMTP id AA23232
  4.   (5.65c/IDA-1.4.4 for <tex-k@cs.umb.edu>); Fri, 17 Dec 1993 08:00:30 -0500
  5. Received: by next18pg2.wam.umd.edu id AA00635
  6.   (5.65c/IDA-1.4.4 for tex-k@cs.umb.edu); Fri, 17 Dec 1993 08:00:29 -0500
  7. Date: Fri, 17 Dec 1993 08:00:29 -0500
  8. From: Joseph Roundtree <savior@wam.umd.edu>
  9. Message-Id: <199312171300.AA00635@next18pg2.wam.umd.edu>
  10. Received: by NeXT Mailer (1.63.RR)
  11. To: tex-k@cs.umb.edu
  12. Subject: Subject: Selected files from the TeXview-a9 source
  13.  
  14. Dear Mr. Berry:                    December 17.1993
  15.  
  16. I am including these files which seem to relate to directory  
  17. searching in TeXview:
  18.  
  19. paths.h-----------------------------------------------------
  20. /*
  21.  *   This software is Copyright 1988 by Radical Eye Software.
  22.  *   All Rights Reserved.
  23.  */
  24. /*
  25.  *   This is the paths file for dviamiga.
  26.  */
  27. /*
  28.  *   PKPATH is where to search for packed files, directories  
  29. separated by
  30.  *   commas.  A period means the current directory (don't prepend  
  31. anything.)
  32.  *   TFMPATH is the same for TFM files.
  33.  */
  34. #define    TFMPATH      
  35. ".:/LocalLibrary/Fonts/TeXFonts/tfm:/usr/lib/tex/fonts/tfm"
  36. #define PKPATH       
  37. ".:/LocalLibrary/Fonts/TeXFonts/pk:/usr/lib/tex/fonts/pk"
  38. #define VFPATH       
  39. ".:/LocalLibrary/Fonts/TeXFonts/vf:/usr/lib/tex/fonts/vf"
  40. #define RESFONTSFILE "psfonts.map"
  41. #define CONFIGPATH ".:/usr/lib/tex/ps"
  42. #define INPUTSPATH   ".:/usr/lib/tex/inputs"
  43.  
  44.  
  45.  
  46. search.c------------------------------------------------------------- 
  47. /*
  48.  *   The search routine takes a directory list, separated by PATHSEP,  
  49. and
  50.  *   tries to open a file.  Null directory components indicate  
  51. current
  52.  *   directory. if the file SUBDIR exists and the file is a font  
  53. file,
  54.  *   it checks for the file in a subdirectory named the same as the  
  55. font name.
  56.  *   Returns the open file descriptor if ok, else NULL.
  57.  */
  58. #include "structures.h" /* The copyright notice in that file is  
  59. included too! */
  60. #define DIRSEP '/'
  61. #define PATHSEP ':'
  62. #include <stdio.h>              /* for FILE and fopen */
  63. #ifdef SYSV
  64. #include <string.h>
  65. #define MAXPATHLEN (128)
  66. #else   /* ~SYSV */
  67. #include <sys/param.h>          /* for MAXPATHLEN */
  68. #include <strings.h>            /* for strlen */
  69. #endif  /* ~SYSV */
  70. #include <pwd.h>
  71. /*
  72.  *
  73.  *   We hope MAXPATHLEN is enough -- only rudimentary checking is  
  74. done!
  75.  */
  76. extern void error() ;
  77. #ifdef DEBUG
  78. extern integer debug_flag;
  79. #endif  /* DEBUG */
  80. char *mfmode ;
  81. extern int actualdpi ;
  82. #define mode "r"
  83. FILE *
  84. search(path, file)
  85.         char *path, *file ;
  86. {
  87.    extern char *getenv(), *newstring() ;
  88.    register char *nam ;                 /* index into fname */
  89.    register FILE *fd ;                  /* file desc of file */
  90.    char fname[MAXPATHLEN] ;             /* to store file name */
  91.    static char *home = 0 ;              /* home is where the heart is  
  92. */
  93.    if (*file == DIRSEP) {               /* if full path name */
  94.       if ((fd=fopen(file,mode)) != NULL)
  95.          return(fd) ;
  96.       else
  97.          return(NULL) ;
  98.    }
  99.  
  100.    do {
  101.       /* copy the current directory into fname */
  102.       nam = fname;
  103.       /* copy till PATHSEP */
  104.       if (*path == '~') {
  105.          char *p = nam ;
  106.          path++ ;
  107.          while (*path && *path != PATHSEP && *path != DIRSEP)
  108.             *p++ = *path++ ;
  109.          *p = 0 ;
  110.          if (*nam == 0) {
  111.             if (home == 0) {
  112.                if (home = getenv("HOME"))
  113.                   home = newstring(home) ;
  114.                else
  115.                   home = "." ;
  116.             }
  117.             strcpy(fname, home) ;
  118.          } else {
  119.             struct passwd *pw = getpwnam(fname) ;
  120.             if (pw)
  121.                strcpy(fname, pw->pw_dir) ;
  122.             else
  123.                error("no such user") ;
  124.          }
  125.          nam = fname + strlen(fname) ;
  126.       }
  127.       while (*path != PATHSEP && *path) *nam++ = *path++;
  128.       *nam = 0 ;
  129.       if (nam == fname) *nam++ = '.';   /* null component is current  
  130. dir */
  131.  
  132.       if (*file != '\0') {
  133.          *nam++ = DIRSEP;                  /* add separator */
  134.          (void)strcpy(nam,file);                   /* tack the file  
  135. on */
  136.       }
  137.       else
  138.          *nam = '\0' ;
  139.  
  140.       /* belated check -- bah! */
  141.       if ((nam - fname) + strlen(file) + 1 > MAXPATHLEN)
  142.          error("! overran allocated storage in search()");
  143.       if ((fd=fopen(fname,mode)) != NULL)
  144.          return(fd);
  145.  
  146.    /* skip over PATHSEP and try again */
  147.    } while (*(path++));
  148.  
  149.    return(NULL);
  150.  
  151. }               /* end search */
  152.  
  153. FILE *
  154. pksearch(path, file, n, dpi)
  155.         char *path, *file ;
  156.     char *n ;
  157.     halfword dpi ;
  158. {
  159.    extern char *getenv(), *newstring() ;
  160.    register char *nam ;                 /* index into fname */
  161.    register FILE *fd ;                  /* file desc of file */
  162.    char fname[MAXPATHLEN] ;             /* to store file name */
  163.    static char *home = 0 ;              /* home is where the heart is  
  164. */
  165.    int sub ;
  166.  
  167.    if (*file == DIRSEP) {               /* if full path name */
  168.       if ((fd=fopen(file,mode)) != NULL)
  169.          return(fd) ;
  170.       else
  171.          return(NULL) ;
  172.    }
  173.    do {
  174.       /* copy the current directory into fname */
  175.       nam = fname;
  176.       sub = 0 ;
  177.       /* copy till PATHSEP */
  178.       if (*path == '~') {
  179.          char *p = nam ;
  180.          path++ ;
  181.          while (*path && *path != PATHSEP && *path != DIRSEP)
  182.             *p++ = *path++ ;
  183.          *p = 0 ;
  184.          if (*nam == 0) {
  185.             if (home == 0) {
  186.                if (home = getenv("HOME"))
  187.                   home = newstring(home) ;
  188.                else
  189.                   home = "." ;
  190.             }
  191.             strcpy(fname, home) ;
  192.          } else {
  193.             struct passwd *pw = getpwnam(fname) ;
  194.             if (pw)
  195.                strcpy(fname, pw->pw_dir) ;
  196.             else
  197.                error("no such user") ;
  198.          }
  199.          nam = fname + strlen(fname) ;
  200.       }
  201.       /* copy till PATHSEP */
  202.       while (*path != PATHSEP && *path) {
  203.          if (*path == '%') {
  204.             sub = 1 ;
  205.             path++ ;
  206.             switch(*path) {
  207.                case 'd': sprintf(nam, "%d", dpi) ; break ;
  208.                case 'f': strcpy(nam, n) ; break ;
  209.                case 'm': if (mfmode == 0)
  210.                             if (actualdpi == 300) mfmode = "imagen" ;
  211.                             else if (actualdpi == 400) mfmode =  
  212. "nexthi" ;
  213.                             else if (actualdpi == 635) mfmode =  
  214. "linolo" ;
  215.                             else if (actualdpi == 1270) mfmode =  
  216. "linohi" ;
  217.                             else if (actualdpi == 2540) mfmode =  
  218. "linosuper" ;
  219.                          if (mfmode == 0)
  220.                             error("! MF mode not set, but used in pk  
  221. path") ;
  222.                          strcpy(nam, mfmode) ;
  223.                          break ;
  224.                case 'p': strcpy(nam, "pk") ; break ;
  225.                case '%': strcpy(nam, "%") ; break ;
  226.                default: error("! bad format character in pk path") ;
  227.             }
  228.             nam = fname + strlen(fname) ;
  229.             if (*path)
  230.                path++ ;
  231.          } else
  232.             *nam++ = *path++;
  233.       }
  234.       if (nam == fname) *nam++ = '.';   /* null component is current  
  235. dir */
  236.  
  237.       if (sub == 0 && *file) {
  238.          *nam++ = DIRSEP ;
  239.          strcpy(nam, file) ;
  240.       } else
  241.          *nam = '\0' ;
  242.  
  243.       /* belated check -- bah! */
  244.       if (strlen(fname) + 1 > MAXPATHLEN)
  245.          error("! overran allocated storage in search()");
  246.       if ((fd=fopen(fname,mode)) != NULL)
  247.          return(fd);
  248.  
  249.    /* skip over PATHSEP and try again */
  250.    } while (*(path++));
  251.  
  252.    return(NULL);
  253.  
  254. }               /* end search */
  255.  
  256. I hope that these are of some use.
  257.  
  258.                         Thank You
  259.                         Joseph Roundtree
  260.                         <savior@wam.umd.edu>
  261.